﻿using System;
using System.ComponentModel;

namespace XchangeStreamer.OutputSdk.ViewModel
{
    [Serializable]
    public sealed class Trade : INotifyPropertyChanged
    {
        #region Private Fields

        private decimal price;
        private uint quantity;
        private TimeSpan time;
        private string ticketNumber;
        private string symbolCode;

        #endregion

        #region Constructors

        private Trade()
        { }

        public Trade(string symbolCode, string ticketNumber, decimal price, uint quantity, TimeSpan time)
        {
            this.symbolCode = symbolCode;
            this.ticketNumber = ticketNumber;
            this.price = price;
            this.quantity = quantity;
            this.time = time;
        }

        #endregion

        #region Public Properties

        public string SymbolCode
        {
            get
            {
                return this.symbolCode;
            }
            set
            {
                if (this.symbolCode != value)
                {
                    this.symbolCode = value;
                    this.InvokePropertyChanged("SymbolCode");
                }
            }
        }

        public string TicketNumber
        {
            get
            {
                return this.ticketNumber;
            }
            set
            {
                if (this.ticketNumber != value)
                {
                    this.ticketNumber = value;
                    this.InvokePropertyChanged("TicketNumber");
                }
            }
        }

        public decimal Price
        {
            get
            {
                return this.price;
            }
            set
            {
                if (this.price != value)
                {
                    this.price = value;
                    this.InvokePropertyChanged("Price");
                }
            }
        }

        public uint Quantity
        {
            get
            {
                return this.quantity;
            }
            set
            {
                if (this.quantity != value)
                {
                    this.quantity = value;
                    this.InvokePropertyChanged("Quantity");
                }
            }
        }

        public TimeSpan Time
        {
            get
            {
                return this.time;
            }
            set
            {
                if (this.time != value)
                {
                    this.time = value;
                    this.InvokePropertyChanged("Time");
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void InvokePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                try
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
                }
                catch { }
            }
        }

        #endregion

        public string GetValue(string propName)
        {
            switch (propName)
            {
                case "SymbolCode":
                    return this.symbolCode;
                case "TicketNumber":
                    return this.ticketNumber;
                case "Price":
                    return this.price.ToString();
                case "Quantity":
                    return this.quantity.ToString();
                case "Time":
                    return this.time.ToString();
                default:
                    return null;
            }
        }
    }
}
